package org.uni_hi.muus;

import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

import org.uni_hi.muus.bluetooth.BluetoothServer;
import org.uni_hi.muus.server.WebServer;

public class MuuSMidlet extends MIDlet {
	
	private Display _display=null;

	private static WebServer _webServer=null;
	private static BluetoothServer _bluetoothServer=null;
	
	public void startApp() {
		_display=Display.getDisplay(this);
		//_display.setCurrent(new Alert("MuuS active"));
		try {
			if(_bluetoothServer==null)_bluetoothServer=new BluetoothServer();
			if(_webServer==null)_webServer=new WebServer("800");
		} catch (IOException e) {
			//TODO: set an notify on the display, that the server was not able to start
//			_display.setCurrent(); 
			e.printStackTrace();
		}
	}

	/**
	 * Pause, discontinue ....
	 */
	public void pauseApp() {
		if(_webServer!=null)_webServer.pauseApp();
		if(_bluetoothServer!=null)_bluetoothServer.pauseApp();
		//_display.setCurrent(new Alert("MuuS paused"));
	}

	/**
	 * Destroy. Cleanup everything.
	 */
	public void destroyApp(boolean unconditional) {
		if(_webServer!=null)_webServer.destroyApp(unconditional);
		if(_bluetoothServer!=null)_bluetoothServer.destroyApp(unconditional);
	}
	
}
